<?php
class ControllerCommonResetPassword extends Controller {
	private $error = array();
	public function index() {
		$userid = $this->request->get['forgottenid'];
		$tokenget = $this->request->get['token'];
		$sandu = $this->cache->get($userid."sandu");
		$salt = $this->cache->get($userid."salt");
		$token = sha1($salt . sha1($salt . sha1($sandu)));
		if ($tokenget != $token){
			$data['error_token'] = "认证错误，请从新发送密码重置邮件！";
		}
		if(($this->request->server['REQUEST_METHOD'] == 'POST')) {
			$userid = $this->request->post['userid'];
			$password = $this->request->post['password'];
			$this->load->model('user/user');
	 		if ($this->model_user_user->resetPassword($userid,$password)) {
	 			$this->cache->delete($userid."sandu");
	 			$this->cache->delete($userid."salt");
	 			header('Content-Type:application/json; charset=utf-8');
                exit(json_encode(1,0));
	 		} else {
	 			$this->cache->delete($userid."sandu");
	 			$this->cache->delete($userid."salt");
	 			header('Content-Type:application/json; charset=utf-8');
                exit(json_encode(0,0));
	 		}
		}
		$this->document->setTitle("resetpassword");
		$data['userid'] = $userid;
		$data['loginurl'] = $this->url->link('common/login', '', true);
		$data['resetpassword'] = $this->url->link('common/resetpassword', '', true);
		$data['header'] = $this->load->controller('common/headerout');
 		$data['footerout'] = $this->load->controller('common/footerout');
 		$data['footer'] = $this->load->controller('common/footer');
 		$this->response->setOutput($this->load->view('common/resetpassword', $data));
	}
}